package com.joysuch.wwyt.mh.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.enums.Status;
import com.joysuch.wwyt.mh.entity.ScreenMapConfig;
import com.joysuch.wwyt.mh.service.ScreenMapConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author heqifeng
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/mh/screen-map-config")
@Api(tags = "大屏地图配置")
public class ScreenMapConfigController {

    @Autowired
    private ScreenMapConfigService screenMapConfigService;

    /**
     * 获取当前公司的大屏配置信息
     * @return
     */
    @GetMapping("/getConfig")
    @ApiOperation(value = "获取配置信息")
    public ResultBean getConfig(){
        ScreenMapConfig configItem = screenMapConfigService.getConfig();
        return ResultBean.success(configItem);
    }

    /**
     * 保存或更新配置
     * @param screenMapConfig
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "保存更新配置")
    public ResultBean update(@RequestBody ScreenMapConfig screenMapConfig){
        if (screenMapConfig == null){
            return ResultBean.fail(Status.PARAMETER_ERROR);
        }
        boolean saved = screenMapConfigService.saveOrUpdate(screenMapConfig);
        if (saved){
            return ResultBean.defaultSuccessResult();
        }
        return ResultBean.fail(Status.OPEN_SERVICE_FAILED);
    }

}